package sfs

import (
	"net"
	"strings"
)

type IP struct {
	Net  string
	Addr string
}

func GetIP() []IP {

	itfs, e := net.Interfaces()
	if e != nil {
		panic(e)
	}

	ips := []IP{}

	for _, itf := range itfs {

		if !strings.Contains(itf.Flags.String(), "up") {
			continue
		}

		addrs, e := itf.Addrs()
		if e != nil {
			panic(e)
		}

		for _, addr := range addrs {
			ip := addr.(*net.IPNet).IP.To4()
			if ip != nil {
				ips = append(ips, IP{
					Net:  itf.Name,
					Addr: ip.String(),
				})
			}
		}
	}

	return ips
}
